package com.valveinspectionsys.routing.BaseAdapter;

import java.util.List;

import com.valveinspectionsys.R;
import com.valveinspectionsys.povo.ListViewInfo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class DeviceListInfoAdapter extends BaseAdapter{
    
    private List<ListViewInfo> items;
    private LayoutInflater inflater;
    
    public DeviceListInfoAdapter (List<ListViewInfo> items, Context context){
	super();
	this.items = items;
	this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
	// TODO Auto-generated method stub
	return items.size();
    }

    @Override
    public Object getItem(int arg0) {
	// TODO Auto-generated method stub
	return items.get(arg0);
    }

    @Override
    public long getItemId(int position) {
	// TODO Auto-generated method stub
	return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
	ViewHolder  holder=null;
	ListViewInfo  info=items.get(position);
	if(convertView==null){
	    convertView = inflater.inflate(R.layout.device_list_item, null);
	    holder=new ViewHolder();
	    holder.viewInfo=(TextView)convertView.findViewById(R.id.device_list_item_info);
	    holder.viewNumber=(TextView)convertView.findViewById(R.id.device_list_item_number);
	    convertView.setTag(holder);
	}else{
	    holder=(ViewHolder)convertView.getTag();
	}
	holder.viewInfo.setText(info.getWaterinfo());
	holder.viewNumber.setText(info.getNumber());
	return convertView;
    }
   
    public class ViewHolder {
	public TextView viewNumber;
	public TextView viewInfo;
    }
}
